import { FC, useEffect, useState } from "react"
import styles from "./PatientInfo.less"
import LabelWraper from "@/components/LabelWraper"
import LabelCard, { columnsProps } from "@/components/LabelCard"
import { FileTextOutlined } from "@ant-design/icons"
import TextList, { TextType } from "@/components/TextList"
import { history, connect, Dispatch, Loading } from "umi"
import { IDetailState } from "@/models/consultationDetailModel"
import { ConsultationDetailProp } from "../index"
import { IConsultUserL, IConsultReport, IConsultHistory } from "@/services/consultationDetail"
import ConsultHistoryItem from "../ConsultHistoryItem/ConsultHistoryItem"


/**
 * 患者基本信息
 */

const columnsCard: columnsProps = [
  {
    label: "姓名",
    prop: "patientName",
    rowId: 1
  },
  {
    label: "性别",
    prop: "patientSexRes",
    rowId: 1
  },
  {
    label: "年龄",
    prop: "patientAge",
    rowId: 1
  },
  {
    label: "住院号",
    prop: "patientCard",
    rowId: 2
  },
  {
    label: "申请科室",
    prop: "deptName",
    rowId: 2
  },
  {
    label: "",
    prop: "aa",
    rowId: 2
  },
  {
    label: "主要诊断",
    prop: "diagnosis",
    rowId: 3
  }
]

/**
 * 参数类型及说明
 */

const consultHistoryTypeList: Array<TextType> = [
  {
    prop: "time",
    propDesc: "时间"
  },
  {
    prop: "description",
    propDesc: "详情"
  }

]

/**
 * 数据列表
 */
let consultHistoryTList: Array<IConsultHistory> = [
  // {
  //   time: "2018.02~2019.03",
  //   desc: "共给予三次腰穿及靴注治疗，颅压基本正常",
  //   other: "其他的信息",
  // },
  // {
  //   time: "2018.02~2019.03",
  //   desc: "共给予三次腰穿及靴注治疗颅压基本正常；治疗时L-ASP皮试两分钟为阳性未使用",
  //   other: "其他的信息",
  // },
  // {
  //   time: "2018.02~2019.03",
  //   desc: "共给予三次腰穿及靴注治疗，颅压基本正常",
  //   other: "其他的信息",
  // }
]



type PatientInfoProp = ConsultationDetailProp

const patientInfo: FC<PatientInfoProp> = ({ conDetail, dispatch, loading }) => {

  const [consultReport, setConsultReport] = useState<IConsultReport>()
  const [consultHistoryItem, setConsultHistoryItem] = useState<IConsultHistory>()

  /**
   * 初始化数据
   */

  const initPatientInfo = () => {
    (conDetail?.consultReport) && (setConsultReport(conDetail.consultReport));
    (conDetail?.consultReport?.consultHistoryList) && (consultHistoryTList = conDetail.consultReport.consultHistoryList);
    (conDetail.consultReport && conDetail.consultReport.consultHistoryList.length > 0) && (setConsultHistoryItem(conDetail.consultReport.consultHistoryList[0]))
  }

  // 选择历史病历
  const selectHistoryCard = (id: number) => {
    const newconsultHistoryItem: IConsultHistory | undefined = consultHistoryTList.find(item => item.id === id)
    setConsultHistoryItem(newconsultHistoryItem)
  }

  useEffect(() => {
    initPatientInfo()
  }, [conDetail.consultReport])

  const baseLoading = loading.models.conDetail.consultReport

  return (
    <div className={styles.patientInfoBox}>
      <LabelWraper
        loading={baseLoading}
        label="基础信息"
        labelWraperHeaderClass={styles.labelWraperHeaderClass}
        labelTextClass={styles.labelTextClass}
        labelWraperBodyClass={styles.labelWraperBodyClass}>
        <LabelCard columns={columnsCard} model={consultReport ? consultReport : {}} />
      </LabelWraper>
      <LabelWraper
        loading={baseLoading}
        label="简要病史"
        labelWraperHeaderClass={styles.labelWraperHeaderClass}
        labelTextClass={styles.labelTextClass}
        labelWraperBodyClass={styles.labelWraperBodyClass}>
        <TextList selectCard={selectHistoryCard} textTypeList={consultHistoryTypeList} modelList={consultHistoryTList} />
      </LabelWraper>
      <LabelWraper
        loading={baseLoading}
        label="检查"
        labelWraperHeaderClass={styles.labelWraperHeaderClass}
        labelTextClass={styles.labelTextClass}
        labelWraperBodyClass={styles.labelWraperBodyClass}>
        <ConsultHistoryItem consultHistoryItem={consultHistoryItem} />
      </LabelWraper>

    </div>
  )
}


const mapStateToProps = ({ conDetail, loading }: { conDetail: IDetailState, loading: Loading }) => {
  return {
    conDetail,
    loading
  }
}
export default connect(mapStateToProps)(patientInfo)